package com.yl.googleplayer_yl.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yl.googleplayer_yl.utils.CommonUtils;

/**
 * Created by Administrator on 2016/10/31 0031.
 */

public abstract class BaseFragment extends Fragment {

    protected PagerLoad loadPage;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (loadPage == null) {
            loadPage = new PagerLoad(getActivity()) {
                @Override
                protected View initSuccessView() {
                    return getSuccessView();
                }

                @Override
                protected Object initData() {
                    return requestData();
                }
            };
        } else {
            CommonUtils.removeSelfFromParent(loadPage);

        }
        return loadPage;
    }

    /**
     * 获取每个子类的view
     *
     * @return
     */
    protected abstract View getSuccessView();

    /**
     * 请求各个子类的数据
     *
     * @return
     */
    protected abstract Object requestData();
}
